package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.system.domain.bo.BaseAuditBo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysLoanVo;
import com.xjy.system.domain.bo.SysLoanQueryBo;
import com.xjy.system.domain.bo.SysLoanAddBo;
import com.xjy.system.domain.bo.SysLoanEditBo;
import com.xjy.system.service.ISysLoanService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 个人借款信息Controller
 *
 * @author xjy
 * @date 2022-02-10
 */
@Api(value = "个人借款信息控制器", tags = {"个人借款信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/loan")
public class SysLoanController extends BaseController {

    private final ISysLoanService iSysLoanService;

    /**
     * 查询个人借款信息列表
     */
    @ApiOperation("查询个人借款信息列表")
    @PreAuthorize("@ss.hasPermi('system:loan:list')")
    @GetMapping("/list")
    public TableDataInfo<SysLoanVo> list(@Validated SysLoanQueryBo bo) {
        return iSysLoanService.queryPageList(bo);
    }

	/**
	 * 查询个人借款信息列表
	 */
	@ApiOperation("查询个人借款信息列表")
	@PreAuthorize("@ss.hasPermi('system:loan:list')")
	@GetMapping("/selectList")
	public List<SysLoanVo> selectList(@Validated SysLoanQueryBo bo) {
		return iSysLoanService.querySelectList();
	}
    /**
     * 导出个人借款信息列表
     */
    @ApiOperation("导出个人借款信息列表")
    @PreAuthorize("@ss.hasPermi('system:loan:export')")
    @Log(title = "个人借款信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysLoanVo> export(@Validated SysLoanQueryBo bo) {
        List<SysLoanVo> list = iSysLoanService.queryList(bo);
		ExcelUtil<SysLoanVo> util = new ExcelUtil<>(SysLoanVo.class);
        return util.exportExcel(list, "个人借款信息");
    }

    /**
     * 获取个人借款信息详细信息
     */
    @ApiOperation("获取个人借款信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:loan:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysLoanVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysLoanService.queryById(id));
    }

    /**
     * 新增个人借款信息
     */
    @ApiOperation("新增个人借款信息")
    @PreAuthorize("@ss.hasPermi('system:loan:add')")
    @Log(title = "个人借款信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysLoanAddBo bo) {
        return toAjax(iSysLoanService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改个人借款信息
     */
    @ApiOperation("修改个人借款信息")
    @PreAuthorize("@ss.hasPermi('system:loan:edit')")
    @Log(title = "个人借款信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("edit")
    public AjaxResult<Void> edit(@Validated @RequestBody SysLoanEditBo bo) {
        return toAjax(iSysLoanService.updateByEditBo(bo) ? 1 : 0);
    }

	/**
	 * 修改个人借款信息
	 */
	@ApiOperation("修改个人借款信息")
	@PreAuthorize("@ss.hasPermi('system:loan:audit')")
	@Log(title = "个人借款信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("audit")
	public synchronized AjaxResult<Void> audit(@Validated @RequestBody BaseAuditBo bo) {
		return toAjax(iSysLoanService.auditByEditBo(bo) ? 1 : 0);
	}


	/**
     * 删除个人借款信息
     */
    @ApiOperation("删除个人借款信息")
    @PreAuthorize("@ss.hasPermi('system:loan:remove')")
    @Log(title = "个人借款信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysLoanService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
